package com.aaa.controller.sas;

import com.aaa.controller.BaseController;
import com.aaa.entity.Result;
import com.aaa.entity.sas.PageSortEntity;
import com.aaa.entity.sas.TestPlanSas;
import com.aaa.service.sas.TestPlanSasService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 测试计划sas(TestPlanSas)表控制层
 *
 * @author makejava
 * @since 2022-08-31 16:41:05
 */
@RestController
@RequestMapping("testPlanSas")
public class TestPlanSasController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private TestPlanSasService testPlanSasService;


/**
 * 去显示所有测试计划的页面
 */
@RequestMapping("toShowTestPlanSas.do")
public ModelAndView toShowTestPlanSas(ModelAndView modelAndView){
    modelAndView.setViewName("sas/showTestPlanSas");
    return modelAndView;

}

    /**
     * 分页查询
     *
     * @param testPlanSas 筛选条件
     * @param testPlanSas      查询条件对象
     * @return 查询结果
     */

  @RequestMapping("queryByPage.do")
  public Result queryByPage(PageSortEntity pageSortEntity, TestPlanSas testPlanSas){
      List<TestPlanSas> planSasList=testPlanSasService.queryByPage(pageSortEntity,testPlanSas);
      Page page= (Page) planSasList;

      return success(page.getTotal(),page.getResult());
  }

    /**
     * 新增数据
     *
     * @param testPlanSas 实体
     * @return 新增结果
     */
    @RequestMapping("insertUser.do")
    public Result insertUser(TestPlanSas testPlanSas){
        int insertSasPlan = testPlanSasService.insertSasPlan(testPlanSas);
        if (insertSasPlan>0){
            return success();
        }else {
            return fail();
        }

    }
    /**
     * 编辑数据
     *
     * @param testPlanSas 实体
     * @return 编辑结果
     */
    @RequestMapping("update.do")
    public Result updateUser(TestPlanSas testPlanSas){
        int updateSasPlan = testPlanSasService.updateSasPlan(testPlanSas);
        if (updateSasPlan>0){
            return success();
        }else {
            return fail();
        }
    }


    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @RequestMapping("delete.do")
    public Result delete(int[] id){
        boolean b =testPlanSasService.deleteByIdSas(id);
        if (b){
            return success("删除成功");
        }
        return fail("删除失败");

    }
    @GetMapping("repetitionName.do")
    public Result repetitionName(TestPlanSas testPlanSas){
        boolean b = this.testPlanSasService.repetitionName(testPlanSas);
        if (b){
            return success("计划名称可用");
        }
        return fail("计划名称重复，不可用");
    }

}

